package com.wanghlme.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanghlme.bookstore.mapper.AddressMapper;
import com.wanghlme.bookstore.service.AddressService;
import com.wanghlme.bookstore.entity.Address;
import com.wanghlme.bookstore.util.common.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WangHailong
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address>
        implements AddressService {

    /**
     * 新增地址信息并返回地址 ID
     *
     * @param address 地址信息
     * @return 地址 ID
     */
    @Override
    public String insertAddress(Address address) {
        if (address == null) {
            return null;
        }
        return save(address) ? address.getAddressId() : null;
    }

    /**
     * 查找该用户所有的地址
     *
     * @param userinfoId 用户 ID
     * @return 用户地址信息列表
     */
    @Override
    public List<Address> listAddressByUserinfoId(String userinfoId) {
        if (StringUtil.isNullEmptyBlank(userinfoId)) {
            return null;
        }
        return list(new QueryWrapper<Address>().eq("userinfo_id", userinfoId));
    }
}




